package org.study.module.jdk;

import org.study.entity.ClusterInfoEntity;
import org.study.entity.ClusterModuleInfoEntity;
import org.study.module.common.ModuleCommon;

import java.util.ArrayList;
import java.util.List;

/**
 * jdk安装
 */
public class JdkShellBuilder {
    private List<String> commands;

    public JdkShellBuilder() {
        commands = new ArrayList<>();
    }

    public JdkShellBuilder existVersion() {
        commands.add("jdk_v=`java -version`");
        commands.add("if [[ $jdk_v == *\"jdk\"* ]]; then");
        commands.add("    echo \"JDK已安装！版本$jdk_v！\"");
        commands.add("    exit 1");
        commands.add("fi");
        return this;
    }


    public JdkShellBuilder check() {
        commands.add("java -version");
        return this;
    }

    public JdkShellBuilder install(ClusterInfoEntity infoEntity, ClusterModuleInfoEntity moduleMode) {
        commands.addAll(ModuleCommon.installByTar(infoEntity, moduleMode));
        return this;
    }

    public List<String> toList() {
        return commands;
    }
}
